from rest_framework.generics import ListAPIView
from rest_framework.response import Response
from rest_framework.views import APIView

from leisurely.serializer.activity_list import ActivityListSerializers
from six_it.models import Gathering


# class ActivityApiView(APIView):
#
#     def get(self, request):
#
#         gathering = Gathering.objects.all()
#
#         serializers = ActivityList(gathering)
#
#         return Response({'results': serializers.data})


class ActivityLisView(ListAPIView):

    queryset = Gathering.objects.all().order_by('id')
    serializer_class = ActivityListSerializers

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        # 分页
        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)
        # 序列化
        serializer = self.get_serializer(queryset, many=True)
        return Response({"results": serializer.data})





